package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Address;
import com.itheima.reggie.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AddressController {

    @Autowired
    private AddressService addressService;


    // 查询收货地址列表
    /*
        请求方式:GET
        请求地址：http://localhost:8081/address/list
        返回值： List<Address>
     */
    @GetMapping("/address/list")
    public ResultInfo list(){
        List<Address> list = addressService.list();
        return ResultInfo.success(list);
    }


    // 新增收货地址
    @PostMapping("/address")
    public ResultInfo add(@RequestBody Address address){
        addressService.add(address);
        return ResultInfo.success();
    }


    // 设置默认地址
    @PutMapping("/address/default")
    public ResultInfo setDefault(@RequestBody Address address){
        addressService.setDefault(address);
        return ResultInfo.success();
    }

    // 查询默认地址
    @GetMapping("/address/default")
    public ResultInfo findDefault(){
        Address address = addressService.findDefault();
        return ResultInfo.success(address);
    }
}
